Skip to content

[spmd_types] fix spmd->DTensor translation on partial mesh - #3913

Merged
pianpwk merged 12 commits into
mainfrom
gh/pianpwk/68/head
Aug 11, 2026
Merged

[spmd_types] fix spmd->DTensor translation on partial mesh#3913
pianpwk merged 12 commits into
mainfrom
gh/pianpwk/68/head

Conversation

@pianpwk

@pianpwk pianpwk commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

translating {DP: V, TP: *} into DTensor (default backend) was failing, even though DP wasn't part of the mesh. Fix by only translating on present axes

Stack from ghstack (oldest at bottom):

pianpwk added 2 commits July 13, 2026 13:08
[ghstack-poisoned]
[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 13, 2026
@pianpwk pianpwk changed the title [spmd_types] fix SpmdLayout placement resolution [spmd_types] fix spmd->DTensor translation on partial mesh Jul 13, 2026
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Jul 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

translating {DP: V, TP: *} into DTensor (default backend) was failing, even though DP wasn't part of the mesh.

Sounds related to https://github.com/pytorch/torchtitan/pull/3895/changes#r3574804150, so putting a hold. The previous invariance seems

  • there's not local activations passing between global module boundary

This PR breaks it in two ways

  • there could be local activations passing between global module boundary
  • there would be config-based redistribute on local activations across global module boundary

Both sounds unsafe, especially (2) which sounds very hacky. Please think about safer solutions. Worst case I'm OK with (1), but redistribute on the local activations should be banned at boundary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there would be config-based redistribute on local activations across global module boundary

tbh, I don't think spmd_types has restrictions on redistribution relations b/w inner/outer axes, e.g. you can do {DP: V, TP: I} -> {DP: I, TP: I}, spmd_types treats this as an allgather on dim 0. Since V in titan might be any kind of varying, I've banned V redistributions in this PR for now?

pianpwk added 4 commits July 29, 2026 06:33
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk
pianpwk requested a review from tianyu-l July 31, 2026 11:36
pianpwk added 2 commits August 6, 2026 16:35
[ghstack-poisoned]
[ghstack-poisoned]
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Aug 6, 2026
pianpwk added 2 commits August 7, 2026 11:39
[ghstack-poisoned]
[ghstack-poisoned]
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Aug 7, 2026
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Aug 7, 2026
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Aug 7, 2026
Comment on lines +236 to +246
if changed_axes and (
src_types[changed_axes[0]] is spmd.V
or dst_types[changed_axes[0]] is spmd.V
):
axis = changed_axes[0]
raise ValueError(
f"{name}: SpmdLayout-based redistribution changes mesh axis "
f"{axis.value!r} with spmd.V as the source or destination type. "
"Config-based redistribution requires non-V types; write an "
"explicit collective when the value semantics are unclear."
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question 1: why only guarding on index [0]?

question 2: in addition to spmd.V, how about spmd.P?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question 1: why only guarding on index [0]?

This is the "src/dst redistribution can only redistribute one axis" thing, so it's just indexing the one redistribution.

question 2: in addition to spmd.V, how about spmd.P?

P src should be fine, I assume you mean P dst? fwiw we do support convert(R/I/S -> P), with the zero-ing out, or zero-padding: https://github.com/meta-pytorch/spmd_types/blob/60705234a3ebb7a2ddd423cb3259f80985d270b2/spmd_types/_local.py#L912-L999

we actually do support V->I/R (assumed as dim 0 allgather), but I'm banning as V could be interpreted as generally different values/shapes

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After offline discussion, this makes sense, but also a bit hard to maintain. But we'll probably move away from this code soon, so having this sounds good for now.

[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk
pianpwk changed the base branch from gh/pianpwk/68/base to main August 11, 2026 17:57
@pianpwk
pianpwk merged commit 801fe17 into main Aug 11, 2026
11 checks passed
pianpwk added a commit that referenced this pull request Aug 12, 2026
after #3913 broke this

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0)
(oldest at bottom):
* __->__ #4128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants